package com.ymatou.iapi.auth.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.auth.parameter.SignAuthBean;
import com.ymatou.iapi.auth.parameter.TokenDeleteBean;
import com.ymatou.iapi.auth.service.TokenDeleteCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*删除token
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_TokenDelete{
	private static TokenDeleteBean tokendeleteBean;
	private static TokenDeleteCall tokendeleteCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("删除token");
	}

	@Before
	public void caseUp() {
		tokendeleteBean=new TokenDeleteBean();
		tokendeleteCall=new TokenDeleteCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(tokendeleteCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TokenDelete_001() {
		Logger.start(true,"删除指定渠道token成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String AccessToken=AuthCallServiceV2.createToken(uid, "wxapp");
			
			tokendeleteBean.setTokenSource("wxapp");
			tokendeleteBean.setUserId(uid);
			tokendeleteCall.setData(tokendeleteBean);
			tokendeleteCall.callService();
			
			Logger.verifyEquals("200", tokendeleteCall.getString("Code"), "验证Code");
			Logger.verifyEquals("true", tokendeleteCall.getString("Success"), "验证Success");
			Thread.sleep(1000);
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(AccessToken);
			sab.setTokenSource("wxapp");
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
//	@Ignore
	//现在按照deviceid
	public void Tc_TokenDelete_002() {
		Logger.start(true,"不输入TokenSource删除全部token");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String AccessToken=AuthCallServiceV2.createToken(uid, "wxapp");
			String AccessToken2=AuthCallServiceV2.createToken(uid, null);
			
//			tokendeleteBean.setTokenSource("wxapp");
			tokendeleteBean.setUserId(uid);
			tokendeleteCall.setData(tokendeleteBean);
			tokendeleteCall.callService();
			
			Logger.verifyEquals("200", tokendeleteCall.getString("Code"), "验证Code");
			Logger.verifyEquals("true", tokendeleteCall.getString("Success"), "验证Success");
			Thread.sleep(1000);
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(AccessToken);
//			sab.setTokenSource("wxapp");
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			sab.setTokenSource("wxapp");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_TokenDelete_003() {
		Logger.start(true,"不输入uid失败");
		try {
			tokendeleteBean.setTokenSource("wxapp");
//			tokendeleteBean.setUserId(uid);
			tokendeleteCall.setData(tokendeleteBean);
			tokendeleteCall.callService();
			
			Logger.verifyEquals("100", tokendeleteCall.getString("Code"), "验证Code");
			Logger.verifyEquals("false", tokendeleteCall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_TokenDelete_004() {
		Logger.start(true,"删除指定渠道token其他可渠道正常校验");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String AccessToken=AuthCallServiceV2.createToken(uid, "wxApp");
			String appAccessToken=AuthCallServiceV2.createToken(uid, "app");
			
			tokendeleteBean.setTokenSource("wxapp");
			tokendeleteBean.setUserId(uid);
			tokendeleteCall.setData(tokendeleteBean);
			tokendeleteCall.callService();
			
			Logger.verifyEquals("200", tokendeleteCall.getString("Code"), "验证Code");
			Logger.verifyEquals("true", tokendeleteCall.getString("Success"), "验证Success");
			Thread.sleep(1000);
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(AccessToken);
			sab.setTokenSource("Wxapp");
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			sab.setToken(appAccessToken);
			sab.setTokenSource("app");
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//这个case待定？
	public void Tc_TokenDelete_005() {
		Logger.start(true,"按照deviceid删除token");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			int uid = JUserCallService.createUserCall(cur);
			String did=TestDataManager.getRandomUUID().toString();
			String did2=TestDataManager.getRandomUUID().toString();
			String AccessToken=AuthCallServiceV2.createToken(uid, "wxapp",did);
			String AccessToken2=AuthCallServiceV2.createToken(uid, "app",did2);
			
//			tokendeleteBean.setTokenSource("wxapp");
			tokendeleteBean.setUserId(uid);
			tokendeleteBean.setDeviceId(did);
			tokendeleteCall.setData(tokendeleteBean);
			tokendeleteCall.callService();
			
			Logger.verifyEquals("200", tokendeleteCall.getString("Code"), "验证Code");
			Logger.verifyEquals("true", tokendeleteCall.getString("Success"), "验证Success");
			SignAuthBean sab=new SignAuthBean();
			sab.setToken(AccessToken);
			sab.setTokenSource("wxapp");
			sab.setDeviceId(did);
			Map<String, Object> m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(false, m.get("success"), "验证Success");
			sab.setToken(AccessToken2);
			sab.setTokenSource("app");
			sab.setDeviceId(did2);
			m = AuthCallServiceV2.signAuth(sab);
			Logger.verifyEquals(true, m.get("success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}